from fontTools.ttLib import TTFont

# 字符绘制
def get_ttf(ttfname, word, line):
    # 加载TTF文件
    SystemDrive = __import__('os').getenv("SystemDrive") # 系统盘符
    font = TTFont(SystemDrive+"Windows\\Fonts\\"+ttfname) # 字体文件
    # 字符的unicode名称
    uni = 'uni'+(hex(ord(word))[2:]).upper()
    # 获取字符的顶点信息
    font_ = font['glyf'][uni]
    # 字符的顶点坐标（转折点）
    outline_pts = font_.coordinates
    # 字符的封闭轮廓的顶点序列(列表)
    outline_i = font_.endPtsOfContours
    # 字符绘制
    outlines = []
    start = 0
    for i in outline_i:
        outlines.append(outline_pts[start:i+1])
        start = i+1
    for pts in outlines:
        ps = (pts[-1][0]+50, 300-pts[-1][1]) # 坐标系的调整
        for pt in pts:
            pe = (pt[0]+50, 300-pt[1])
            line(ps, pe) # 绘图
            ps = pe


# 简单的窗口绘图
if __name__ == '__main__':
    from graphics import GraphWin,Line,Point
    win = GraphWin("文字", 500,500) # 窗口
    win.setBackground('#ffffff')
    # 调用函数绘图
    line = lambda ps,pe:Line(Point(*ps), Point(*pe)).draw(win)
    get_ttf("simkai.ttf", "礁", line)
    win.getMouse() # 等待鼠标响应，退出程序
    win.close()